package springcloud.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @Author 咕唧
 * @Date 2022/6/28 11:51
 * @Version 1.0
 */
@Component
public class MyRouteFilter extends ZuulFilter {
    /**
     * 路由过滤器
     *
     * @return
     */
    @Override
    public String filterType() {
        return FilterConstants.ROUTE_TYPE;
    }

    @Override
    public int filterOrder() {
        return FilterConstants.PRE_DECORATION_FILTER_ORDER+100;
    }

    @Override
    public boolean shouldFilter() {
        RequestContext currentContext = RequestContext.getCurrentContext();
        return currentContext.sendZuulResponse();
    }

    @Override
    public Object run() throws ZuulException {
        //我们过滤器要执行的操作
        System.err.println("MyrouteFilter中的方法run 执行了");
        return null;
    }
}
